package com.example.xlzx.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xlzx.entity.User;
import com.example.xlzx.result.Result;
import com.example.xlzx.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 1
 * @since 2025-03-07
 */
@RestController
@Tag(name="用户信息")
@RequestMapping("/xlzx")
public class UserController {
    @Autowired
    private IUserService userService;

    @Operation(summary = "用户注册")
    @PostMapping("/insetUser")
    public Result<Boolean> insertUser(@RequestBody User user) {
        return Result.ok(userService.insetUser(user));
    }

    @Operation(summary = "根据id删除用户")
    @DeleteMapping("/deleteUser/{id}")
    public Result<Boolean> deleteUser(@PathVariable Long id) {
        return Result.ok(userService.removeById(id));
    }

    @Operation(summary = "修改用户信息")
    @PutMapping("/updateUser")
    public Result<Boolean> updateUser(@RequestBody User user) {
        return Result.ok(userService.updateUser(user));
    }

    @Operation(summary = "根据id查询用户信息")
    @GetMapping("/getUserInfo/{id}")
    public Result<User> getUserInfo(@PathVariable Long id) {
        return Result.ok(userService.getById(id));
    }

    @Operation(summary = "用户分页查询")
    @GetMapping("/selectUser/page")
    public Result<Page<User>> selectUser(@RequestParam(required = false) String userRealName, @RequestParam(required = false) Integer type, @RequestParam int page, @RequestParam int size) {
        Page<User> pageParam = new Page<>(page, size);
        Page<User> userPage = userService.selectUser(userRealName, type,pageParam);
        return Result.ok(userPage);
    }
}
